﻿using NUnit.Framework;

namespace HappyTemplate.Tests
{
	[TestFixture]
	public class ParserErrorTests : TestFixtureHelper
	{
		[Test]
		[ExpectedException(typeof(AbortParseException))]
		public void	EofInTemplateCausesInfiniteLoop()
		{
			TemplateSet ts = ParseTemplateSetNoCatch("TestTemplate()<{<$test$>");
			//TODO:  ensure error collection contains proper message
		}

		[Test]
		[ExpectedException(typeof(AbortParseException))]
		public void EofInCodeSectionCausesInfiniteLoop()
		{
			TemplateSet ts = ParseTemplateSetNoCatch("testTemplate() <{<$test");
			//TODO:  ensure error collection contains proper message
		}

		[Test]
		[ExpectedException(typeof(AbortParseException))]
		public void EofInParameterListCausesInfiniteLoop()
		{
			TemplateSet ts = ParseTemplateSetNoCatch("testTemplate(");
			//TODO:  ensure error collection contains proper message
		}

		[Test]
		[ExpectedException(typeof(AbortParseException))]	
		public void EofInArgumentListCausesInfiniteLoop()
		{
			Template ts = ParseTemplateNoCatch("<$callMe(");
			//TODO:  ensure error collection contains proper message
		}

		[Test]
		[ExpectedException(typeof(AbortParseException))]	
		public void OmitNextKeyword()
		{
			ParseTemplateSetNoCatch("<$foreach(s in n) \"don't go into an infinite loop\"$>");
		}

		[Test]
		public void DuplicateLookupValue()
		{
			TemplateSet ts = ParseTemplateSetNoCatch(@"
lookup hasDuplicatedValue
{
	""nonDuplicateInputValue1"" = ""outputValue1"",
	""duplicateInputValue"" = ""outputValue2"",
	""nonDuplicateInputValue2"" = ""outputValue3"",
	""duplicateInputValue"" = ""outputValue4""
}");
			
			Assert.AreEqual(1, _sourceErrors.Count);

			//TODO:
//			Assert.AreEqual(Resources.TemplateErrorMessages.DuplicateInputValue_Value.ToString(), 
//				_sourceErrors[0].Message);
		}

		[Test]
		[ExpectedException(typeof(AbortParseException))]
		public void UnterminatedTemplate()
		{
			TemplateSet ts = ParseTemplateSetNoCatch(@" testTemplate() <{");
			//TODO:  ensure error collection contains proper message
		}
	}
}
